package com.wang.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.wang.common.utils.R;
import com.wang.gulimall.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Created: with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-07-08 13:39
 **/

@Controller
public class MemberWebController {

    @Autowired
    private OrderFeignService orderFeignService;

    //支付宝支付成功后成功跳转到此页面 查询该用户下面的订单及订单状态
    // 同步回调通知缺点 :若用户关闭浏览器则修改不了订单的状态 此时支付宝服务器和用户系统的订单状态就不一致了
    @GetMapping(value = "/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum",required = false,defaultValue = "0") Integer pageNum,
                                  Model model,
                                  HttpServletRequest request) {
        //获取到支付宝给我们转来的所有请求数据
        //request,验证签名

        //查出当前登录用户的所有订单列表数据
        Map<String, Object> page = new HashMap<>();
        page.put("page", pageNum.toString());

        //远程查询订单服务订单数据
        R orderInfo = orderFeignService.listWithItem(page);
        System.out.println(JSON.toJSONString(orderInfo));
        model.addAttribute("orders", orderInfo);
        return "orderList";
    }
}
